//: ChequeBean.java 17.09.2008 11:24:24Z apt $
package com.devunion.salon.web.bean;

import com.devunion.salon.persistence.Cheque;

import java.util.ArrayList;
import java.util.List;


/**
 * @author Timoshenko Alexander
 */
public class ChequeBean {
    private String number;
    private List<EmployeeBean> employees;
    private CustomerBean customerBean;
    private PaymentBean payment;
    private PaymentBean secondPayment;
    private Float discount;
    private Float reminder;
    private List<TransactionBean> transactions;
    private Float totalPrice;
    private Float totalTaxes;
    private Integer totalItems;
    private Float totalPriceAndTaxes;

    public ChequeBean() {
        transactions = new ArrayList<TransactionBean>();
        employees = new ArrayList<EmployeeBean>();
    }

    public ChequeBean(Cheque cheque) {
        this();
        this.number = cheque.getNumber();
        this.payment = new PaymentBean(cheque.getPayment());
        if (cheque.getSecondPayment() != null) {
            this.secondPayment = new PaymentBean(cheque.getSecondPayment());
        }
        this.discount = cheque.getDiscount();
        this.reminder = cheque.getReminder();
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public PaymentBean getPayment() {
        return payment;
    }

    public void setPayment(PaymentBean payment) {
        this.payment = payment;
    }

    public PaymentBean getSecondPayment() {
        return secondPayment;
    }

    public void setSecondPayment(PaymentBean secondPayment) {
        this.secondPayment = secondPayment;
    }

    public Float getDiscount() {
        return discount;
    }

    public void setDiscount(Float discount) {
        this.discount = discount;
    }

    public Float getReminder() {
        return reminder;
    }

    public void setReminder(Float reminder) {
        this.reminder = reminder;
    }

    public List<TransactionBean> getTransactions() {
        return transactions;
    }

    public void setTransactions(List<TransactionBean> transactions) {
        this.transactions = transactions;
    }

    public List<EmployeeBean> getEmployees() {
        return employees;
    }

    public void setEmployees(List<EmployeeBean> employees) {
        this.employees = employees;
    }

    public Float getTotalPrice() {
        this.totalPrice = 0f;
        for (TransactionBean bean : transactions) {
            this.totalPrice += bean.getPrice();
        }

        return totalPrice;
    }

    public void setTotalPrice(Float totalPrice) {
        this.totalPrice = totalPrice;
    }

    public Float getTotalTaxes() {
        this.totalTaxes = 0f;
        for (TransactionBean bean : transactions) {
            this.totalTaxes += bean.getTaxes();
        }
        return totalTaxes;
    }

    public void setTotalTaxes(Float totalTaxes) {
        this.totalTaxes = totalTaxes;
    }

    public Integer getTotalItems() {
        this.totalItems = 0;
        for (TransactionBean bean : transactions) {
            if (bean.getProduct() != null) {
                this.totalItems += bean.getQuantity();
            } else {
                this.totalItems++;
            }
        }
        return totalItems;
    }

    public void setTotalItems(Integer totalItems) {
        this.totalItems = totalItems;
    }

    public Float getTotalPriceAndTaxes() {
        this.totalPriceAndTaxes = 0f;
        for (TransactionBean bean : transactions) {
            this.totalPriceAndTaxes += bean.getTotal();
        }
        return totalPriceAndTaxes;
    }

    public void setTotalPriceAndTaxes(Float totalPriceAndTaxes) {
        this.totalPriceAndTaxes = totalPriceAndTaxes;
    }

    public CustomerBean getCustomerBean() {
        return customerBean;
    }

    public void setCustomerBean(CustomerBean customerBean) {
        this.customerBean = customerBean;
    }
}
